<!--suppress ALL -->
<template>
  <div class="login_page fillcontain" @keyup.enter="submitForm('loginForm')">
    <transition name="form-fade" mode="in-out">
      <section class="form_contianer" v-show="showLogin">
        <div class="manage_tip">
          <p>惠优品后台</p>
        </div>
        <el-form :model="loginForm" :rules="rules" ref="loginForm">
          <el-form-item prop="username">
            <el-input v-model="loginForm.username" placeholder="用户名"></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input type="password" placeholder="密码" v-model="loginForm.password"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('loginForm')" class="submit_btn">登陆</el-button>
          </el-form-item>
        </el-form>
      </section>
    </transition>
  </div>
</template>

<script>
  import {lgabh,userinfo, ajax} from '../../data/service'
  import * as config from '../../config/const';

  export default {
    data(){
      return {
        loginForm: {
          username: '',
          password: '',
        },
        rules: {
          username: [
            { required: true, message: '请输入用户名', trigger: 'blur' },
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' }
          ],
        },
        showLogin: false,
      }
    },
    mounted(){
      this.showLogin = true;
    },
    created(){
      //如果已经登陆了，直接登走
      this.checkLogin();
    },
    computed: {
    },
    mixins:[ajax],
    methods: {
      async submitForm(formName){
        this.$refs[formName].validate(async (valid) => {
          if (valid) {
            this.doajax(lgabh,this.loginForm,(resp) =>{
              this.$router.push(config.AUTH_FILTER.admin.successUrl);
            });
          }else{
            this.error('请输入正确的用户名密码');
          }
        });
      },
      checkLogin(){
        this.doajax(userinfo,{},(resp) => {
          sessionStorage.setItem(config.SESSION_KEY,'autostringify-'+JSON.stringify(resp.info));
          this.$router.push(config.AUTH_FILTER.admin.successUrl);
        },(err) => {
          sessionStorage.removeItem(config.SESSION_KEY);
        });
      }
    },
    watch: {
    }
  }
</script>

<style lang="less" scoped>
  @import '../../style/mixin';
  .login_page{
    background-color: #324057;
  }
  .manage_tip{
    position: absolute;
    width: 100%;
    top: -100px;
    left: 0;
  p{
    font-size: 34px;
    color: #fff;
  }
  }
  .form_contianer{
  .wh(320px, 170px);
  .ctp(320px, 170px);
    padding: 25px;
    border-radius: 5px;
    text-align: center;
    background-color: #fff;
  .submit_btn{
    width: 100%;
    font-size: 16px;
  }
  }
  .tip{
    font-size: 12px;
    color: red;
  }
  .form-fade-enter-active, .form-fade-leave-active {
    transition: all 1s;
  }
  .form-fade-enter, .form-fade-leave-active {
    transform: translate3d(0, -50px, 0);
    opacity: 0;
  }
</style>
<style lang="less">
  @import '../../style/common';

  .params{
    padding:10px ;
  }
  .params label{
    margin-left: 10px;
  }
  .pagetools{
    padding-top: 10px;
    height: 100px;
  }
</style>
